package com.itheima.provider;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

/**
 * @program: spring-cloud-parent
 * @description:
 * @author: zhanghz001
 * @create: 2021-02-05 13:54
 **/
@Component
@EnableBinding(Source.class)
public class MessageProducer {
    @Autowired
    private MessageChannel output;
    
    public void send() {
        String message = "hello stream~~~";
        //发送消息
        output.send(MessageBuilder.withPayload(message).build());
        System.out.println("消息发送成功");
    }
}
